package org.dtrd.modules.evaluation.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.evaluation.entity.bean.PersonalityInfo;
import org.dtrd.modules.evaluation.entity.po.DtrdEntEvaluationRdPersonality;
import org.dtrd.modules.evaluation.mapper.DtrdEntEvaluationRdPersonalityMapper;
import org.dtrd.modules.evaluation.service.IDtrdEntEvaluationRdPersonalityService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.StringJoiner;

/**
 * <p>
 * 卡尔特16种人格因素评估 服务实现类
 * </p>
 *
 * @author QR
 * @since 2021-09-26
 */
@Service
@DS("multi-datasource1")
public class DtrdEntEvaluationRdPersonalityServiceImpl extends ServiceImpl<DtrdEntEvaluationRdPersonalityMapper, DtrdEntEvaluationRdPersonality> implements IDtrdEntEvaluationRdPersonalityService {

    @Override
    public PersonalityInfo savePersonalityInfo(PersonalityInfo personalityInfo) {
        List<Integer> answerArr = personalityInfo.getInput();
        StringJoiner joiner = new StringJoiner(",");
        int tmpScore = 0;

        int fa = 0;
        int fb = 0;
        int fc = 0;
        int fe = 0;
        int ff = 0;
        int fg = 0;
        int fh = 0;
        int fi = 0;
        int fl = 0;
        int fm = 0;
        int fn = 0;
        int fo = 0;
        int fq1 = 0;
        int fq2 = 0;
        int fq3 = 0;
        int fq4 = 0;
        for (int i = 0; i < answerArr.size(); i++) {
            tmpScore = answerArr.get(i);
            joiner.add(tmpScore+"");
            switch (i) {
                case 2:
                case 51:
                case 100:
                case 125:
                case 175:
                    fa += (2 - tmpScore);
                    break;
                case 25:
                case 26:
                case 50:
                case 75:
                case 150:
                    fa += tmpScore;
                    break;
                case 176:
                case 177:
                    if (tmpScore == 0)
                        fb += 1;
                    break;
                case 27:
                case 52:
                case 53:
                case 77:
                case 102:
                case 127:
                case 151:
                    if (tmpScore == 1)
                        fb += 1;
                    break;
                case 76:
                case 101:
                case 126:
                case 152:
                    if (tmpScore == 2)
                        fb += 1;
                    break;
                case 3:
                case 29:
                case 54:
                case 103:
                case 104:
                case 128:
                case 129:
                case 178:
                    fc += (2 - tmpScore);
                    break;
                case 4:
                case 28:
                case 78:
                case 79:
                case 153:
                    fc += tmpScore;
                    break;
                case 6:
                case 55:
                case 130:
                case 154:
                case 155:
                case 179:
                case 180:
                    fe += (2 - tmpScore);
                    break;
                case 5:
                case 30:
                case 31:
                case 56:
                case 80:
                case 105:
                    fe += tmpScore;
                    break;
                case 32:
                case 57:
                case 131:
                case 132:
                case 181:
                case 182:
                    ff += (2 - tmpScore);
                    break;
                case 7:
                case 81:
                case 82:
                case 106:
                case 107:
                case 156:
                case 157:
                    ff += tmpScore;
                    break;
                case 58:
                case 108:
                case 133:
                case 159:
                case 183:
                case 184:
                    fg += (2 - tmpScore);
                    break;
                case 8:
                case 33:
                case 83:
                case 158:
                    fg += tmpScore;
                    break;
                case 9:
                case 35:
                case 109:
                case 110:
                case 135:
                case 185:
                    fh += (2 - tmpScore);
                    break;
                case 34:
                case 59:
                case 60:
                case 84:
                case 85:
                case 134:
                case 160:
                    fh += tmpScore;
                    break;
                case 36:
                case 111:
                case 137:
                case 162:
                    fi += (2 - tmpScore);
                    break;
                case 10:
                case 11:
                case 61:
                case 86:
                case 136:
                case 161:
                    fi += tmpScore;
                    break;
                case 12:
                case 37:
                case 87:
                case 112:
                case 113:
                case 163:
                    fl += (2 - tmpScore);
                    break;
                case 62:
                case 63:
                case 88:
                case 138:
                    fl += tmpScore;
                    break;
                case 38:
                case 39:
                case 64:
                case 90:
                case 114:
                case 139:
                    fm += (2 - tmpScore);
                    break;
                case 13:
                case 14:
                case 89:
                case 115:
                case 140:
                case 164:
                case 165:
                    fm += tmpScore;
                    break;
                case 41:
                case 116:
                case 141:
                case 166:
                    fn += (2 - tmpScore);
                    break;
                case 15:
                case 16:
                case 40:
                case 65:
                case 66:
                case 91:
                    fn += tmpScore;
                    break;
                case 17:
                case 42:
                case 68:
                case 117:
                case 118:
                case 142:
                case 167:
                    fo += (2 - tmpScore);
                    break;
                case 18:
                case 43:
                case 67:
                case 92:
                case 93:
                case 143:
                    fo += tmpScore;
                    break;
                case 19:
                case 20:
                case 45:
                case 69:
                case 144:
                case 168:
                    fq1 += (2 - tmpScore);
                    break;
                case 44:
                case 94:
                case 119:
                case 169:
                    fq1 += tmpScore;
                    break;
                case 46:
                case 70:
                case 71:
                case 145:
                case 170:
                    fq2 += (2 - tmpScore);
                    break;
                case 21:
                case 95:
                case 96:
                case 120:
                case 121:
                    fq2 += tmpScore;
                    break;
                case 47:
                case 72:
                case 97:
                case 146:
                case 147:
                case 172:
                    fq3 += (2 - tmpScore);
                    break;
                case 22:
                case 23:
                case 122:
                case 171:
                    fq3 += tmpScore;
                    break;
                case 24:
                case 48:
                case 49:
                case 73:
                case 98:
                case 123:
                case 148:
                case 149:
                case 173:
                    fq4 += (2 - tmpScore);
                    break;
                case 74:
                case 99:
                case 124:
                case 174:
                    fq4 += tmpScore;
                    break;
                default:
                    break;
            }
        }
        int fa_score = 0;
        int fb_score = 0;
        int fc_score = 0;
        int fe_score = 0;
        int ff_score = 0;
        int fg_score = 0;
        int fh_score = 0;
        int fi_score = 0;
        int fl_score = 0;
        int fm_score = 0;
        int fn_score = 0;
        int fo_score = 0;
        int fq1_score = 0;
        int fq2_score = 0;
        int fq3_score = 0;
        int fq4_score = 0;
        if (fa <= 1) {
            fa_score = 1;
        } else if (fa <= 3) {
            fa_score = 2;
        } else if (fa <= 5) {
            fa_score = 3;
        } else if (fa <= 6) {
            fa_score = 4;
        } else if (fa <= 8) {
            fa_score = 5;
        } else if (fa <= 11) {
            fa_score = 6;
        } else if (fa <= 13) {
            fa_score = 7;
        } else if (fa <= 14) {
            fa_score = 8;
        } else if (fa <= 16) {
            fa_score = 9;
        } else if (fa <= 20) {
            fa_score = 10;
        }
        if (fb <= 3) {
            fb_score = 1;
        } else if (fb <= 4) {
            fb_score = 2;
        } else if (fb <= 5) {
            fb_score = 3;
        } else if (fb <= 6) {
            fb_score = 4;
        } else if (fb <= 7) {
            fb_score = 5;
        } else if (fb <= 8) {
            fb_score = 6;
        } else if (fb <= 9) {
            fb_score = 7;
        } else if (fb <= 10) {
            fb_score = 8;
        } else if (fb <= 11) {
            fb_score = 9;
        } else if (fb <= 13) {
            fb_score = 10;
        }
        if (fc <= 5) {
            fc_score = 1;
        } else if (fc <= 7) {
            fc_score = 2;
        } else if (fc <= 9) {
            fc_score = 3;
        } else if (fc <= 11) {
            fc_score = 4;
        } else if (fc <= 13) {
            fc_score = 5;
        } else if (fc <= 16) {
            fc_score = 6;
        } else if (fc <= 18) {
            fc_score = 7;
        } else if (fc <= 20) {
            fc_score = 8;
        } else if (fc <= 22) {
            fc_score = 9;
        } else if (fc <= 26) {
            fc_score = 10;
        }
        if (fe <= 2) {
            fe_score = 1;
        } else if (fe <= 4) {
            fe_score = 2;
        } else if (fe <= 5) {
            fe_score = 3;
        } else if (fe <= 7) {
            fe_score = 4;
        } else if (fe <= 9) {
            fe_score = 5;
        } else if (fe <= 12) {
            fe_score = 6;
        } else if (fe <= 14) {
            fe_score = 7;
        } else if (fe <= 16) {
            fe_score = 8;
        } else if (fe <= 18) {
            fe_score = 9;
        } else if (fe <= 26) {
            fe_score = 10;
        }
        if (ff <= 3) {
            ff_score = 1;
        } else if (ff <= 4) {
            ff_score = 2;
        } else if (ff <= 6) {
            ff_score = 3;
        } else if (ff <= 7) {
            ff_score = 4;
        } else if (ff <= 9) {
            ff_score = 5;
        } else if (ff <= 12) {
            ff_score = 6;
        } else if (ff <= 14) {
            ff_score = 7;
        } else if (ff <= 16) {
            ff_score = 8;
        } else if (ff <= 18) {
            ff_score = 9;
        } else if (ff <= 26) {
            ff_score = 10;
        }
        if (fg <= 5) {
            fg_score = 1;
        } else if (fg <= 7) {
            fg_score = 2;
        } else if (fg <= 9) {
            fg_score = 3;
        } else if (fg <= 10) {
            fg_score = 4;
        } else if (fg <= 12) {
            fg_score = 5;
        } else if (fg <= 14) {
            fg_score = 6;
        } else if (fg <= 16) {
            fg_score = 7;
        } else if (fg <= 17) {
            fg_score = 8;
        } else if (fg <= 18) {
            fg_score = 9;
        } else if (fg <= 20) {
            fg_score = 10;
        }
        if (fh <= 1) {
            fh_score = 1;
        } else if (fh <= 2) {
            fh_score = 2;
        } else if (fh <= 3) {
            fh_score = 3;
        } else if (fh <= 6) {
            fh_score = 4;
        } else if (fh <= 8) {
            fh_score = 5;
        } else if (fh <= 11) {
            fh_score = 6;
        } else if (fh <= 14) {
            fh_score = 7;
        } else if (fh <= 16) {
            fh_score = 8;
        } else if (fh <= 19) {
            fh_score = 9;
        } else if (fh <= 26) {
            fh_score = 10;
        }
        if (fi <= 5) {
            fi_score = 1;
        } else if (fi <= 6) {
            fi_score = 2;
        } else if (fi <= 8) {
            fi_score = 3;
        } else if (fi <= 9) {
            fi_score = 4;
        } else if (fi <= 11) {
            fi_score = 5;
        } else if (fi <= 13) {
            fi_score = 6;
        } else if (fi <= 14) {
            fi_score = 7;
        } else if (fi <= 16) {
            fi_score = 8;
        } else if (fi <= 17) {
            fi_score = 9;
        } else if (fi <= 19) {
            fi_score = 10;
        }
        if (fl <= 3) {
            fl_score = 1;
        } else if (fl <= 5) {
            fl_score = 2;
        } else if (fl <= 6) {
            fl_score = 3;
        } else if (fl <= 8) {
            fl_score = 4;
        } else if (fl <= 10) {
            fl_score = 5;
        } else if (fl <= 12) {
            fl_score = 6;
        } else if (fl <= 13) {
            fl_score = 7;
        } else if (fl <= 15) {
            fl_score = 8;
        } else if (fl <= 16) {
            fl_score = 9;
        } else if (fl <= 20) {
            fl_score = 10;
        }
        if (fm <= 5) {
            fm_score = 1;
        } else if (fm <= 7) {
            fm_score = 2;
        } else if (fm <= 9) {
            fm_score = 3;
        } else if (fm <= 11) {
            fm_score = 4;
        } else if (fm <= 13) {
            fm_score = 5;
        } else if (fm <= 15) {
            fm_score = 6;
        } else if (fm <= 17) {
            fm_score = 7;
        } else if (fm <= 19) {
            fm_score = 8;
        } else if (fm <= 20) {
            fm_score = 9;
        } else if (fm <= 26) {
            fm_score = 10;
        }
        if (fm <= 5) {
            fm_score = 1;
        } else if (fm <= 7) {
            fm_score = 2;
        } else if (fm <= 9) {
            fm_score = 3;
        } else if (fm <= 11) {
            fm_score = 4;
        } else if (fm <= 13) {
            fm_score = 5;
        } else if (fm <= 15) {
            fm_score = 6;
        } else if (fm <= 17) {
            fm_score = 7;
        } else if (fm <= 19) {
            fm_score = 8;
        } else if (fm <= 20) {
            fm_score = 9;
        } else if (fm <= 26) {
            fm_score = 10;
        }
        if (fn <= 2) {
            fn_score = 1;
        } else if (fn <= 3) {
            fn_score = 2;
        } else if (fn <= 4) {
            fn_score = 3;
        } else if (fn <= 6) {
            fn_score = 4;
        } else if (fn <= 8) {
            fn_score = 5;
        } else if (fn <= 10) {
            fn_score = 6;
        } else if (fn <= 11) {
            fn_score = 7;
        } else if (fn <= 13) {
            fn_score = 8;
        } else if (fn <= 14) {
            fn_score = 9;
        } else if (fn <= 20) {
            fn_score = 10;
        }
        if (fo <= 2) {
            fo_score = 1;
        } else if (fo <= 4) {
            fo_score = 2;
        } else if (fo <= 6) {
            fo_score = 3;
        } else if (fo <= 8) {
            fo_score = 4;
        } else if (fo <= 10) {
            fo_score = 5;
        } else if (fo <= 12) {
            fo_score = 6;
        } else if (fo <= 14) {
            fo_score = 7;
        } else if (fo <= 16) {
            fo_score = 8;
        } else if (fo <= 18) {
            fo_score = 9;
        } else if (fo <= 26) {
            fo_score = 10;
        }
        if (fq1 <= 4) {
            fq1_score = 1;
        } else if (fq1 <= 5) {
            fq1_score = 2;
        } else if (fq1 <= 7) {
            fq1_score = 3;
        } else if (fq1 <= 8) {
            fq1_score = 4;
        } else if (fq1 <= 10) {
            fq1_score = 5;
        } else if (fq1 <= 12) {
            fq1_score = 6;
        } else if (fq1 <= 13) {
            fq1_score = 7;
        } else if (fq1 <= 14) {
            fq1_score = 8;
        } else if (fq1 <= 15) {
            fq1_score = 9;
        } else if (fq1 <= 20) {
            fq1_score = 10;
        }
        if (fq2 <= 5) {
            fq2_score = 1;
        } else if (fq2 <= 7) {
            fq2_score = 2;
        } else if (fq2 <= 8) {
            fq2_score = 3;
        } else if (fq2 <= 10) {
            fq2_score = 4;
        } else if (fq2 <= 12) {
            fq2_score = 5;
        } else if (fq2 <= 14) {
            fq2_score = 6;
        } else if (fq2 <= 15) {
            fq2_score = 7;
        } else if (fq2 <= 17) {
            fq2_score = 8;
        } else if (fq2 <= 18) {
            fq2_score = 9;
        } else if (fq2 <= 20) {
            fq2_score = 10;
        }
        if (fq3 <= 4) {
            fq3_score = 1;
        } else if (fq3 <= 6) {
            fq3_score = 2;
        } else if (fq3 <= 8) {
            fq3_score = 3;
        } else if (fq3 <= 10) {
            fq3_score = 4;
        } else if (fq3 <= 12) {
            fq3_score = 5;
        } else if (fq3 <= 14) {
            fq3_score = 6;
        } else if (fq3 <= 15) {
            fq3_score = 7;
        } else if (fq3 <= 17) {
            fq3_score = 8;
        } else if (fq3 <= 18) {
            fq3_score = 9;
        } else if (fq3 <= 20) {
            fq3_score = 10;
        }
        if (fq4 <= 2) {
            fq4_score = 1;
        } else if (fq4 <= 4) {
            fq4_score = 2;
        } else if (fq4 <= 6) {
            fq4_score = 3;
        } else if (fq4 <= 8) {
            fq4_score = 4;
        } else if (fq4 <= 11) {
            fq4_score = 5;
        } else if (fq4 <= 14) {
            fq4_score = 6;
        } else if (fq4 <= 16) {
            fq4_score = 7;
        } else if (fq4 <= 19) {
            fq4_score = 8;
        } else if (fq4 <= 21) {
            fq4_score = 9;
        } else if (fq4 <= 26) {
            fq4_score = 10;
        }

        String fa_level = "";
        String fb_level = "";
        String fc_level = "";
        String fe_level = "";
        String ff_level = "";
        String fg_level = "";
        String fh_level = "";
        String fi_level = "";
        String fl_level = "";
        String fm_level = "";
        String fn_level = "";
        String fo_level = "";
        String fq1_level = "";
        String fq2_level = "";
        String fq3_level = "";
        String fq4_level = "";
        if (fa < 3) {
            fa_level = "低分";
        } else if (fa < 8) {
            fa_level = "中等";
        } else {
            fa_level = "高分";
        }
        if (fb < 3) {
            fb_level = "低分";
        } else if (fb < 8) {
            fb_level = "中等";
        } else {
            fb_level = "高分";
        }
        if (fc < 3) {
            fc_level = "低分";
        } else if (fc < 8) {
            fc_level = "中等";
        } else {
            fc_level = "高分";
        }
        if (fe < 3) {
            fe_level = "低分";
        } else if (fe < 8) {
            fe_level = "中等";
        } else {
            fe_level = "高分";
        }
        if (ff < 3) {
            ff_level = "低分";
        } else if (ff < 8) {
            ff_level = "中等";
        } else {
            ff_level = "高分";
        }
        if (fg < 3) {
            fg_level = "低分";
        } else if (fg < 8) {
            fg_level = "中等";
        } else {
            fg_level = "高分";
        }
        if (fh < 3) {
            fh_level = "低分";
        } else if (fh < 8) {
            fh_level = "中等";
        } else {
            fh_level = "高分";
        }
        if (fi < 3) {
            fi_level = "低分";
        } else if (fi < 8) {
            fi_level = "中等";
        } else {
            fi_level = "高分";
        }
        if (fl < 3) {
            fl_level = "低分";
        } else if (fl < 8) {
            fl_level = "中等";
        } else {
            fl_level = "高分";
        }
        if (fm < 3) {
            fm_level = "低分";
        } else if (fm < 8) {
            fm_level = "中等";
        } else {
            fm_level = "高分";
        }
        if (fn < 3) {
            fn_level = "低分";
        } else if (fn < 8) {
            fn_level = "中等";
        } else {
            fn_level = "高分";
        }
        if (fo < 3) {
            fo_level = "低分";
        } else if (fo < 8) {
            fo_level = "中等";
        } else {
            fo_level = "高分";
        }
        if (fq1 < 3) {
            fq1_level = "低分";
        } else if (fq1 < 8) {
            fq1_level = "中等";
        } else {
            fq1_level = "高分";
        }
        if (fq2 < 3) {
            fq2_level = "低分";
        } else if (fq2 < 8) {
            fq2_level = "中等";
        } else {
            fq2_level = "高分";
        }
        if (fq3 < 3) {
            fq3_level = "低分";
        } else if (fq3 < 8) {
            fq3_level = "中等";
        } else {
            fq3_level = "高分";
        }
        if (fq4 < 3) {
            fq4_level = "低分";
        } else if (fq4 < 8) {
            fq4_level = "中等";
        } else {
            fq4_level = "高分";
        }
        float fx1_score = 0;
        float fx2_score = 0;
        float fx3_score = 0;
        float fx4_score = 0;
        int fy1_score = 0;
        int fy2_score = 0;
        int fy3_score = 0;
        int fy4_score = 0;

        String fx1_level = "";
        String fx2_level = "";
        String fx3_level = "";
        String fx4_level = "";
        String fy1_level = "";
        String fy2_level = "";
        String fy3_level = "";
        String fy4_level = "";
        String output = "";

        // X1＝[(38+2×L+3×O+4×Q4)－(2×C+2×H+2×Q 3)]÷10
        fx1_score = ((38 + 2 * fl_score + 3 * fo_score + 4 * fq4_score) - (2 * fc_score + 2 * fh_score + 2 * fq3_score)) / (float) 10;
        // X2= (2A+3E+4F+5H-2Q2-11)/10
        fx2_score = (2 * fa_score + 3 * fe_score + 4 * ff_score - 2 * fq2_score - 11) / (float) 10;
        // X3=[(77+2×C+2×E+2×F+2×N)－(4×A+6×I+2×M)]÷10
        fx3_score = ((77 + 2 * fc_score + 2 * fe_score + 2 * ff_score + 2 * fn_score) - (4 * fa_score + 6 * fi_score + 2 * fm_score)) / (float) 10;
        // X4=[(4×E+3×M+4×Q1+4×Q2)－(3×A+2×G)]÷10
        fx4_score = ((4 * fe_score + 3 * fm_score + 4 * fq1_score + 4 * fq2_score) - (3 * fa_score + 2 * fg_score)) / (float) 10;
        // Y1=C+F+(11－O)+(11－Q4)
        fy1_score = fc + ff + (11 - fo) + (11 - fq4);
        // Y2=2Q3+2G+2C+E+N+Q2+Q1
        fy2_score = 2 * fq3_score + 2 * fg_score + 2 * fc_score + fe_score + fn_score + fq2_score + fq1_score;
        // Y3=(11－A)×2+B×2+E+(11－F)×2+H+ I×2+M+(11－N)+Q1+Q2×2
        fy3_score = (11 - fa) * 2 + fb * 2 + fe + (11 - ff) * 2 + fh + fi * 2 + fm + (11 - fn) + fq1 + fq2 * 2;
        // Y4=B+G+Q3+(11－F)
        fy4_score = fb + fg + fq3 + (11 - ff);

        if (fx1_score < 2.27) {
            fx1_level = "低分";
        } else if (fx1_score <= 4.83) {
            fx1_level = "中等";
        } else {
            fx1_level = "高分";
        }
        if (fx2_score < 5.61) {
            fx2_level = "低分";
        } else if (fx2_score <= 8.90) {
            fx2_level = "中等";
        } else {
            fx2_level = "高分";
        }
        if (fx3_score < 4.24) {
            fx3_level = "低分";
        } else if (fx3_score <= 6.84) {
            fx3_level = "中等";
        } else {
            fx3_level = "高分";
        }
        if (fx4_score < 3.17) {
            fx4_level = "低分";
        } else if (fx4_score <= 6.34) {
            fx4_level = "中等";
        } else {
            fx4_level = "高分";
        }

        if (fy1_score < 25) {
            fy1_level = "一般";
        } else {
            fy1_level = "高";
        }
        if (fy2_score < 67) {
            fy2_level = "一般";
        } else {
            fy2_level = "高";
        }
        if (fy3_score < 80) {
            fy3_level = "一般";
        } else {
            fy3_level = "高";
        }
        if (fy4_score < 27) {
            fy4_level = "一般";
        } else {
            fy4_level = "高";
        }
        DtrdEntEvaluationRdPersonality info = new DtrdEntEvaluationRdPersonality();
        info.setInput(joiner.toString());
        info.setFaScore(fa_score);
        info.setFaLevel(fa_level);
        info.setFbScore(fb_score);
        info.setFbLevel(fb_level);
        info.setFcScore(fc_score);
        info.setFcLevel(fc_level);
        info.setFeScore(fe_score);
        info.setFeLevel(fe_level);
        info.setFfScore(ff_score);
        info.setFfLevel(ff_level);
        info.setFgScore(fg_score);
        info.setFgLevel(fg_level);
        info.setFhScore(fh_score);
        info.setFhLevel(fh_level);
        info.setFiScore(fi_score);
        info.setFiLevel(fi_level);
        info.setFlScore(fl_score);
        info.setFlLevel(fl_level);
        info.setFmScore(fm_score);
        info.setFmLevel(fm_level);
        info.setFnScore(fn_score);
        info.setFnLevel(fn_level);
        info.setFoScore(fo_score);
        info.setFoLevel(fo_level);
        info.setFq1Score(fq1_score);
        info.setFq1Level(fq1_level);
        info.setFq2Score(fq2_score);
        info.setFq2Level(fq2_level);
        info.setFq3Score(fq3_score);
        info.setFq3Level(fq3_level);
        info.setFq4Score(fq4_score);
        info.setFq4Level(fq4_level);
        info.setFx1Score(fx1_score);
        info.setFx1Level(fx1_level);
        info.setFx2Score(fx2_score);
        info.setFx2Level(fx2_level);
        info.setFx3Score(fx3_score);
        info.setFx3Level(fx3_level);
        info.setFx4Score(fx4_score);
        info.setFx4Level(fx4_level);
        info.setFy1Score(fy1_score);
        info.setFy1Level(fy1_level);
        info.setFy2Score(fy2_score);
        info.setFy2Level(fy2_level);
        info.setFy3Score(fy3_score);
        info.setFy3Level(fy3_level);
        info.setFy4Score(fy4_score);
        info.setFy4Level(fy4_level);
        info.setOutput(output);
        if (info.getPatientId() != null) {
            info.setPatientId(info.getPatientId());
            save(info);
        }
        return new PersonalityInfo().parseFromPo(info);
    }

    @Override
    public PersonalityInfo getPersonalityInfoLatest(Integer patientId) {
        LambdaQueryWrapper<DtrdEntEvaluationRdPersonality> queryWrapper = Wrappers.lambdaQuery(DtrdEntEvaluationRdPersonality.class)
                .eq(DtrdEntEvaluationRdPersonality::getPatientId, patientId)
                .orderByDesc(DtrdEntEvaluationRdPersonality::getCreateTime)
                .last("limit 1");
        DtrdEntEvaluationRdPersonality query = this.getOne(queryWrapper);
        PersonalityInfo personalityInfo = new PersonalityInfo();
        if (query != null) {
            personalityInfo.parseFromPo(query);
        }
        return personalityInfo;
    }
}
